package com.tiancheng.trade.order.util;


import com.tiancheng.trade.order.enums.*;
import com.tiancheng.trade.order.vo.admin.KeyValueVO;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class DictUtil {

    private static String couponStatusEnum = "couponStatus";
    private static String operateCodeEnum = "operateCode";
    private static String orderPayStatusEnum = "orderPayStatus";
    private static String orderSourceEnum = "orderSource";
    private static String orderStatusEnum = "orderStatus";
    private static String orderTypeEnum = "orderType";
    private static String refundStatusEnum = "refundStatus";
    private static String subOrderStatusEnum = "subOrderStatus";

    private static Map<String, List<KeyValueVO>> map = new HashMap<>();


    public static Map<String, List<KeyValueVO>> getDict() {
        return map;
    }

    public static List<KeyValueVO> getDict(String dictType) {
        return map.get(dictType);
    }

    static {
        List<KeyValueVO> couponStatusEnum = Arrays.stream(CouponStatusEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.couponStatusEnum, couponStatusEnum);

        List<KeyValueVO> operateCodeEnum = Arrays.stream(OperateCodeEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.operateCodeEnum, operateCodeEnum);

        List<KeyValueVO> orderPayStatusEnum = Arrays.stream(OrderPayStatusEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.orderPayStatusEnum, orderPayStatusEnum);

        List<KeyValueVO> orderSourceEnum = Arrays.stream(OrderSourceEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.orderSourceEnum, orderSourceEnum);

        List<KeyValueVO> orderStatusEnum = Arrays.stream(OrderStatusEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());

        map.put(DictUtil.orderStatusEnum, orderStatusEnum);


        List<KeyValueVO> orderTypeEnum = Arrays.stream(OrderTypeEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());
        map.put(DictUtil.orderTypeEnum, orderTypeEnum);

        List<KeyValueVO> refundStatusEnum = Arrays.stream(RefundStatusEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());

        map.put(DictUtil.refundStatusEnum, refundStatusEnum);

        List<KeyValueVO> subOrderStatusEnum = Arrays.stream(SubOrderStatusEnum.values()).map(e -> {
            KeyValueVO KeyValueVO = new KeyValueVO();
            KeyValueVO.setKey(e.getCode());
            KeyValueVO.setValue(e.getDesc());
            return KeyValueVO;
        }).collect(Collectors.toList());

        map.put(DictUtil.subOrderStatusEnum, subOrderStatusEnum);

    }
}
